﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Reticulum.User
{
    class ThisMyInfo
    {
        /* 功能：存储目前登录的用户的信息
         * 作者：蒙兰德
         * 编写日期：2020/6/25/22:04
         * 
         * */

        //定义用户属性
        public static string UserID;//用户ID（关联文件）
        public static string UserName;//用户名
        public static string Sex;//性别
        public static string Birthday;//生日
        public static string UserAccount;//账号
        public static string UserPwd;//密码
        public static string UserPhone;//电话
        public static string MySignature;//个性签名
        public static string MyDescription;//个人说明
        public static string Occupational;//职业
        public static string Company;//公司
        public static string Area;//所在地区
        public static string Hometown;//故乡
        public static string Email;//邮箱
        public static string BloodGroup;//血型
        public static string UploadState;//上传权限(0-是同意上传 1-禁止上传)
        public static string DownloadState;//--下载权限(0-是同意下载 1-禁止下载)
        public static string ImagePath;//用户头像地址
        public static string ThisIP;//正在进行登录的IP地址
        public static string VIP;//是否会员



        public static void ThisUser()
        {
            //对登录的用户的信息进行存储
            string DML = string.Format("select * from Users where UserAccount = {0}", LoginHome.account);//LoginHome.account为正在进行登录的账号

            SqlDataReader reader = DBHelps.Select(DML);
            //调用DBHelp类进行查询
            while (reader.Read())
            {
                UserID = reader["UserID"].ToString();
                UserName = reader["UserName"].ToString();
                Sex = reader["Sex"].ToString();
                UserAccount = reader["UserAccount"].ToString();
                UserPwd = reader["UserPwd"].ToString();
                UserPhone = reader["UserPhone"].ToString();
                MySignature = reader["MySignature"].ToString();
                MyDescription = reader["MyDescription"].ToString();
                Occupational = reader["Occupational"].ToString();
                Company = reader["Company"].ToString();
                Area = reader["Area"].ToString();
                Hometown = reader["Hometown"].ToString();
                Email = reader["Email"].ToString();
                BloodGroup = reader["BloodGroup"].ToString();
                UploadState = reader["UploadState"].ToString();
                DownloadState = reader["DownloadState"].ToString();
                ImagePath = reader["ImagePath"].ToString();
                Birthday = reader["Birthday"].ToString();
                ThisIP = GetLocalIp();
                VIP = reader["VIP"].ToString();

            }
            DBHelps.Select(DML).Close();
            DBHelps.reader = null;
        }


        public static string GetLocalIp()
        {
            ///获取本地的IP地址
            string AddressIP = string.Empty;
            foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
            {
                if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                {
                    AddressIP = _IPAddress.ToString();
                }
            }
            return AddressIP;
        }


    }
}
